//
//  AFHTTPSessionManager+Test.m
//  CoreUser
//
//  Created by Demi on 18/04/2017.
//  Copyright © 2017 Azazie. All rights reserved.
//

#import "AFHTTPSessionManager+Test.h"
#import <TXFire/TXFire.h>

@implementation AFHTTPSessionManager (Test)

+ (void)load
{
    SEL originalSelector = NSSelectorFromString(@"base_dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:");
    
    SEL replaceSelector = @selector(test_dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:);
    
    method_exchangeImplementations(class_getInstanceMethod(self, originalSelector), class_getInstanceMethod(self, replaceSelector));
}

- (NSURLSessionDataTask *)test_dataTaskWithHTTPMethod:(NSString *)method
                                            URLString:(NSString *)URLString
                                           parameters:(id)parameters
                                       uploadProgress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgress
                                     downloadProgress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgress
                                              success:(void (^)(NSURLSessionDataTask *, id))success
                                              failure:(void (^)(NSURLSessionDataTask *, NSError *))failure
{
    
    NSURLSessionDataTask *dataTask = [self test_dataTaskWithHTTPMethod:method URLString:URLString parameters:parameters uploadProgress:uploadProgress downloadProgress:downloadProgress success:success failure:failure];
    
    NSData *data = dataTask.currentRequest.HTTPBody;
    NSString *body = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
    TXLogVars(body);
    TXLogVars(dataTask.currentRequest.URL);
    
    return dataTask;
}

@end
